package com.apexedu.portal.action;

import com.apexedu.framework.service.BaseService;
import com.apexedu.framework.util.DBUtil;
import com.apexedu.identity.service.IdMenuService;
import com.apexedu.portal.service.impl.AppSetServiceImpl;
import com.apexedu.sys.action.AbstractBaseActionSupport;
import com.apexedu.sys.entity.ApplicationEnum;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.apexedu.portal.entity.AppFunctionConfig;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * app功能配置
 * Created by janabo on 2014-12-5.
 */
@SuppressWarnings("serial")
@Component
@Scope("prototype")
public class AppSetAction extends AbstractBaseActionSupport {

    private AppFunctionConfig appFunctionConfig;
    private List<String> listIcon;//app服务图标库

    public AppFunctionConfig getAppFunctionConfig() {
        return appFunctionConfig;
    }

    public void setAppFunctionConfig(AppFunctionConfig appFunctionConfig) {
        this.appFunctionConfig = appFunctionConfig;
    }

    /**
     * 此方法植入service类
     */
    @Resource(name="appSetService")
    public void setBaseService(BaseService baseService){
        super.setBaseService(baseService);
    }


    /**
     * 功能类别
     * @return
     */
    public List<ApplicationEnum> getAppFun() {
        String sql = "select t.id as id,t.name as caption from APP_FUNCTION_LIST t order by t.id";
        List<ApplicationEnum> list = DBUtil.queryAllBeanList(sql, ApplicationEnum.class);
        return list;
    }

    /**
     * 选择配置的sql
     * @return
     */
    public List<ApplicationEnum> getAppXX(){
        String sql = "select t.wid as id,t.name as caption from T_LBXX t where t.upid = '3' order by orderno ";
        List<ApplicationEnum> list = DBUtil.queryAllBeanList(sql, ApplicationEnum.class);
        return list;
    }

    /**
     * 父类id
     * @return
     */
    public List<ApplicationEnum> getSuperId(){
        String sql = "select t.id as id,t.name as caption from APP_FUNCTION_CONFIG t order by  style,orderno asc ";
        List<ApplicationEnum> list = DBUtil.queryAllBeanList(sql, ApplicationEnum.class);
        return list;
    }

    /**
     * 展现样式
     * @return
     */
    public List<ApplicationEnum> getAppZxys(){
        List<ApplicationEnum> list = new ArrayList<ApplicationEnum>();
        ApplicationEnum applicationEnum = new ApplicationEnum();
        applicationEnum.setId("2");
        applicationEnum.setCaption("首页顶部菜单");
        list.add(applicationEnum);
        ApplicationEnum applicationEnum2 = new ApplicationEnum();
        applicationEnum2.setId("4");
        applicationEnum2.setCaption("抽屉列表");
        list.add(applicationEnum2);
        return list;
    }

    /**
     * app选项卡角色设置
     * @return
     */
    public String  roleSet(){
        String appmenuid = getRequest().getParameter("wid");
        AppSetServiceImpl service = (AppSetServiceImpl)getBaseService();
        try {
         String checkids = service.getCheckedRole(appmenuid);
            this.setParameter("checkids",checkids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.setParameter("wid",appmenuid);
        return toView("appRolemenu.jsp");
    }

    /**
     * 获取业务系统服务
     *
     * @return
     */
    public void getMenues() {
        AppSetServiceImpl service = (AppSetServiceImpl)getBaseService();
        try {
            putResultStringToView(service.getMenus());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 保存app菜单对应的角色
     */
    public void saveBatchService(){
        AppSetServiceImpl service = (AppSetServiceImpl)getBaseService();
        try {
            service.saveBatchService(getRequest().getParameter("menuids"),getRequest().getParameter("appmenuid"));
            putResultStringToView("ok");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    public List<String> getListIcon() {
        return listIcon;
    }

    public void setListIcon(List<String> listIcon) {
        this.listIcon = listIcon;
    }
}
